package com.zrwl.poscloud.xo.service.impl;
import com.zrwl.poscloud.base.entity.DemoRelation;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zrwl.poscloud.base.enums.EStatus;
import com.zrwl.poscloud.base.superI.SuperServiceImpl;
import com.zrwl.poscloud.commons.utils.ResultUtil;
import com.zrwl.poscloud.commons.utils.StringUtils;
import com.zrwl.poscloud.xo.global.MessageConf;
import com.zrwl.poscloud.xo.global.SQLConf;
import com.zrwl.poscloud.xo.global.SysConf;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import com.zrwl.poscloud.xo.mapper.DemoRelationMapper;
import com.zrwl.poscloud.xo.service.DemoRelationService;
import com.zrwl.poscloud.xo.vo.DemoRelationVO;

import javax.annotation.Resource;

/**
 * 关联演示 服务实现类
 *
 * @author 刘思童 AutoGenerate
 * @date 2022-09-05
 */
@Service
public class DemoRelationServiceImpl extends SuperServiceImpl<DemoRelationMapper,DemoRelation> implements DemoRelationService {

    @Autowired
    private DemoRelationService demoRelationService;
    @Resource
    private DemoRelationMapper demoRelationMapper;
    @Override
    public IPage<DemoRelationVO> getPageList(DemoRelationVO demoRelationVO){
       Page page = new Page<>();
       page.setCurrent(demoRelationVO.getCurrentPage());
       page.setSize(demoRelationVO.getPageSize());
       IPage<DemoRelationVO> pageList = demoRelationMapper.getPageList(page, demoRelationVO);
       List<DemoRelationVO> list = pageList.getRecords();
       pageList.setRecords(list);
       return pageList;
}
    @Override
    public List<DemoRelation> getAllList(DemoRelationVO demoRelationVO){
        QueryWrapper<DemoRelation> queryWrapper = new QueryWrapper<>();
        queryWrapper.ne(SQLConf.STATUS, EStatus.DISABLED);
        queryWrapper.orderByAsc(SQLConf.CREATE_TIME);
        List<DemoRelation> list = demoRelationService.list(queryWrapper);
        return list;
}
    @Override
    public String add(DemoRelationVO demoRelationVO){
        DemoRelation entity = new DemoRelation();
        BeanUtils.copyProperties(demoRelationVO, entity, SysConf.STATUS);
        entity.insert();
        demoRelationVO.setUid(entity.getUid());
        return ResultUtil.successWithMessage(MessageConf.INSERT_SUCCESS);}
    @Override
    public String edit(DemoRelationVO demoRelationVO){
        DemoRelation entity = demoRelationService.getById(demoRelationVO.getUid());
        BeanUtils.copyProperties(demoRelationVO, entity);
        entity.updateById();
        return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
}
    @Override
    public String delete(DemoRelationVO demoRelationVO){
        DemoRelation entity = demoRelationService.getById(demoRelationVO.getUid());
        entity.setStatus(EStatus.DISABLED);
        entity.updateById();
        return ResultUtil.successWithMessage(MessageConf.UPDATE_SUCCESS);
}
}
